import { ReturnRouterInt, InitMenuListInt } from "../types/index"


enum RouterEnum {
    '首页' = 1, "超级签应用", "苹果分发应用", "安卓分发应用", "免签分发应用", "开发账号管理", "用户模块管理"
}

enum IconsEnum {
    'piechartIcon' = 1, "cloudIcon", "appleIcon", "androidIcon", 'AppstoreAddOutlined', "bookIcon", "teamIcon",
}

export function InitMenuListFun(router: ReturnRouterInt[], routerEnum: RouterEnum): InitMenuListInt {
    let InitMenuList: InitMenuListInt[] = [];
    if (routerEnum !== 1) {
        router.forEach((routeritem: ReturnRouterInt) => {
            if (routeritem.unified == routerEnum) {
                const result: boolean = InitMenuList.some((item: InitMenuListInt): boolean => {
                    if (item.title == RouterEnum[routerEnum]) {
                        return true;
                    }
                    return false
                });
                if (!result) {
                    InitMenuList.push({
                        title: RouterEnum[routerEnum],
                        icon: IconsEnum[routerEnum],
                        children: [],
                    });
                }
                InitMenuList.forEach((item: InitMenuListInt): void => {
                    if (item.title == RouterEnum[routerEnum]) {
                        item.children ? item.children.push(routeritem) : []
                    }
                });
            }
        });
    } else {
        router.forEach((routeritem: ReturnRouterInt): void => {
            if (routeritem.unified == routerEnum) {
                const result = InitMenuList.some((item: InitMenuListInt): boolean => {
                    if (item.title == RouterEnum[routerEnum]) {
                        return true;
                    }
                    return false
                });
                if (!result) {
                    InitMenuList.push({
                        icon: IconsEnum[routerEnum],
                        ...routeritem
                    })
                }
            }
        });
    }
    return InitMenuList[0];
}


export function menuList(router: ReturnRouterInt[]): InitMenuListInt[] {
    let unified: number[] = [];
    let InitMenuList: InitMenuListInt[] = [];
    router.forEach((item: ReturnRouterInt) => {
        if (unified.indexOf(item.unified) == -1) {
            unified.push(item.unified);
            InitMenuList.push(InitMenuListFun(router, item.unified));
        }
    });
    return InitMenuList
}

